/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sadhar.sipp.posbiaya;


import org.sadhar.sia.framework.ClassApplicationModule;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 *
 * @author bloodrunk
 */
public class PosBiayaWnd extends ClassApplicationModule{

    private Listbox lstboxPosBiaya;
    private Textbox txtboxSearch;
    private PosBiayaDAO posBiayaDAO;

    public PosBiayaWnd() {
        posBiayaDAO = new PosBiayaDAOImpl();
    }

    public void onCreate() throws Exception {
        lstboxPosBiaya = (Listbox) getFellow("lstboxPosBiaya");
        txtboxSearch = (Textbox) getFellow("txtboxSearch");
        load();
    }

    public void load() throws Exception {
        lstboxPosBiaya.getItems().clear();
        int no = 1;
        for (PosBiaya posBiaya : posBiayaDAO.list(txtboxSearch.getValue())) {
            Listitem item = new Listitem();
            item.setValue(posBiaya);
            item.appendChild(new Listcell("" + no++));          
            item.appendChild(new Listcell(posBiaya.getNamaPosBiaya()));
            lstboxPosBiaya.appendChild(item);
        }
    }

      public void lstboxPosBiayaOnSelect() throws Exception {
        Window windowProduct = (Window) this.getRoot();
        Textbox txtboxKeySearch = (Textbox)windowProduct.getFellow("txtboxKeySearch");
        Textbox txtboxIdPosBiaya = (Textbox)windowProduct.getFellow("txtboxIdPosBiaya");
        PosBiaya posBiaya = (PosBiaya) lstboxPosBiaya.getSelectedItem().getValue();
        txtboxKeySearch.setValue(posBiaya.getNamaPosBiaya());
        txtboxIdPosBiaya.setValue(posBiaya.getKodePosBiaya()+"");
        this.detach();
    }

}
